import 'package:flutter/material.dart';
import 'package:flutter_boost/flutter_boost.dart';
import 'package:power_image/power_image.dart';

void main() {
  CustomFlutterBinding();
  PowerImageLoader.instance.setup(PowerImageSetupOptions(renderingTypeTexture,
      errorCallback: (PowerImageLoadException exception) {
        final Map<dynamic, dynamic> args = <dynamic, dynamic>{};
        (exception?.nativeResult ?? <dynamic, dynamic>{}).forEach((key, value) {
          args[key] = value?.toString() ?? '';
        });
      }));
  runApp(MyApp());
}

class CustomFlutterBinding extends WidgetsFlutterBinding
    with BoostFlutterBinding {}

class MyApp extends StatelessWidget {
  Route<dynamic> routeFactory(RouteSettings settings, String uniqueId) {
    if (settings.name == 'A') {
      return PageRouteBuilder<dynamic>(settings: settings, pageBuilder: (_, __, ___) {
        return PageA();
      });
    } else {
      return PageRouteBuilder<dynamic>(settings: settings, pageBuilder: (_, __, ___) {
        return PageB();
      });
    }
  }

  @override
  Widget build(BuildContext context) {
    return FlutterBoostApp(routeFactory,);
  }
}

class PageA extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: GestureDetector(
          onTap: () {
            BoostNavigator.instance.push('B',
              withContainer: true,
            );
          },
          child: PowerImage.asset('images/IF4.jpg',
            renderingType: renderingTypeTexture,
            width: 300,
            height: 300,
          ),
        ),
      ),
    );
  }
}

class PageB extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: PowerImage.asset('images/IF7.jpg',
          renderingType: renderingTypeTexture,
          width: 300,
          height: 300,
        ),
      ),
    );
  }
}